<?php
/**
 * @authors alex (20779512@qq.com)
 * @date    2014-03-24 17:25:39
 * @version 1.0
 */

class FenxiaoAction extends HomeAction {

    #代理中心
    public function index(){
    	$map['id'] = $this->_user['memberID'];
    	$obj = M('Member');
    	$user = $obj->field('id,fid,wxface,userType,wxname,money,guanzhu,userGroup,createTime')->where($map)->find();
    	$user['fname'] = $obj->where('wxid="'.$user['fid'].'"')->getField('wxname');
    	if ($user['fname']=='') {
    		$user['fname'] = C('site_name');
    	}

        if ($user['userType']==0) {
            $user['shenfen'] = '身份：普通会员';
        }else if($user['userType']==1){
            $user['shenfen'] = '身份：业务员';
        }else if($user['userType']==2){
            $user['shenfen'] = '身份：商家会员';
        }

    	/*if ($list['guanzhu']==0) {
    		$user['shenfen'] = '身份：普通会员';
    	}else{
    		if (C('must_buy')==1) {
	    		if ($user['userGroup']==0) {
	    			$user['shenfen'] = '消费即可成为正式会员坐享佣金';
	    		}else{
	    			$user['shenfen'] = '身份：正式会员';
	    		}
	    	}else{
	    		$user['shenfen'] = '身份：正式会员';
	    	}
    	}*/
    	

    	$obj = M('Member');
    	//我的一级会员
    	unset($map);
    	$map['fid'] = $this->_user['wxid'];
    	$list = $obj->where($map)->getField('id,wxid');
    	$member_1 = count($list);

    	if ($member_1<1) {
    		$img1 = 0;
    	}elseif($member_1>0 && $member_1<=10){
    		$img1 = 1;
    	}elseif($member_1>10 && $member_1<=30){
    		$img1 = 2;
    	}elseif($member_1>30 && $member_1<=50){
    		$img1 = 3;
    	}elseif($member_1>50 && $member_1<=100){
    		$img1 = 4;
    	}elseif($member_1>100 && $member_1<=200){
    		$img1 = 5;
    	}elseif($member_1>200 && $member_1<=500){
    		$img1 = 6;
    	}else{
    		$img1 = 7;
    	}
    	$this->assign('img1',$img1);
    	
    	//我的二级会员
		unset($map);
		$map['fid'] = array('in',$list);
		$list = $obj->where($map)->getField('id,wxid');
		$member_2 = count($list);

		if ($member_2<1) {
    		$img2 = 0;
    	}elseif($member_2>0 && $member_2<=50){
    		$img2 = 1;
    	}elseif($member_2>50 && $member_2<=100){
    		$img2 = 2;
    	}elseif($member_2>100 && $member_2<=200){
    		$img2 = 3;
    	}elseif($member_2>200 && $member_2<=500){
    		$img2 = 4;
    	}elseif($member_2>500 && $member_2<=1000){
    		$img2 = 5;
    	}elseif($member_2>1000 && $member_2<=5000){
    		$img2 = 6;
    	}else{
    		$img2 = 7;
    	}
    	$this->assign('img2',$img2);

		//我的三级会员
		unset($map);
		$map['fid'] = array('in',$list);
		$list = $obj->where($map)->getField('id,wxid');
		$member_3 = count($list);

		if ($member_3<1) {
    		$img3 = 0;
    	}elseif($member_3>0 && $member_3<=50){
    		$img3 = 1;
    	}elseif($member_3>50 && $member_3<=100){
    		$img3 = 2;
    	}elseif($member_3>100 && $member_3<=200){
    		$img3 = 3;
    	}elseif($member_3>200 && $member_3<=500){
    		$img3 = 4;
    	}elseif($member_3>500 && $member_3<=1000){
    		$img3 = 5;
    	}elseif($member_3>1000 && $member_3<=5000){
    		$img3 = 6;
    	}else{
    		$img3 = 7;
    	}
    	$this->assign('img3',$img3);


		$obj = M('Yongjin');
		//一级会员佣金
		$map['toUserID'] = $this->_user['memberID'];
		$map['level'] = 1;
		$money_1 = $obj->where($map)->sum('money');
		if ($money_1 == '') {
			$money_1 = 0;
		}

		if ($money_1<1) {
    		$m1 = 0;
    	}elseif($money_1>0 && $money_1<=500){
    		$m1 = 1;
    	}elseif($money_1>500 && $money_1<=1000){
    		$m1 = 2;
    	}elseif($money_1>1000 && $money_1<=2000){
    		$m1 = 3;
    	}elseif($money_1>2000 && $money_1<=3000){
    		$m1 = 4;
    	}elseif($money_1>3000 && $money_1<=5000){
    		$m1 = 5;
    	}elseif($money_1>5000 && $money_1<=10000){
    		$m1 = 6;
    	}else{
    		$m1 = 7;
    	}
    	$this->assign('m1',$m1);

		//二级会员佣金
		unset($map);
		$map['toUserID'] = $this->_user['memberID'];
		$map['level'] = 2;
		$money_2 = $obj->where($map)->sum('money');
		if ($money_2 == '') {
			$money_2 = 0;
		}

		if ($money_2<1) {
    		$m2 = 0;
    	}elseif($money_2>0 && $money_2<=500){
    		$m2 = 1;
    	}elseif($money_2>500 && $money_2<=1000){
    		$m2 = 2;
    	}elseif($money_2>1000 && $money_2<=3000){
    		$m2 = 3;
    	}elseif($money_2>3000 && $money_2<=5000){
    		$m2 = 4;
    	}elseif($money_2>5000 && $money_2<=10000){
    		$m2 = 5;
    	}elseif($money_2>10000 && $money_2<=20000){
    		$m2 = 6;
    	}else{
    		$m2 = 7;
    	}
    	$this->assign('m2',$m2);

		//三级会员佣金
		unset($map);		
		$map['toUserID'] = $this->_user['memberID'];
		$map['level'] = 3;
		$money_3 = $obj->where($map)->sum('money');
		if ($money_3 == '') {
			$money_3 = 0;
		}

		if ($money_3<1) {
    		$m3 = 0;
    	}elseif($money_3>0 && $money_3<=1000){
    		$m3 = 1;
    	}elseif($money_3>1000 && $money_3<=5000){
    		$m3 = 2;
    	}elseif($money_3>5000 && $money_3<=10000){
    		$m3 = 3;
    	}elseif($money_3>10000 && $money_3<=50000){
    		$m3 = 4;
    	}elseif($money_3>50000 && $money_3<=100000){
    		$m3 = 5;
    	}elseif($money_3>100000 && $money_3<=1000000){
    		$m3 = 6;
    	}else{
    		$m3 = 7;
    	}
    	$this->assign('m3',$m3);

		$money_total = number_format(($money_1+$money_2+$money_3),2);



		$this->assign('member_1',$member_1);
		$this->assign('member_2',$member_2);
		$this->assign('member_3',$member_3);

		$this->assign('buyUser_1',$buyUser_1);
		$this->assign('buyUser_2',$buyUser_2);
		$this->assign('buyUser_3',$buyUser_3);
		$this->assign('buyUser_total',$buyUser_total);

		$this->assign('money_1',$money_1);
		$this->assign('money_2',$money_2);
		$this->assign('money_3',$money_3);
		$this->assign('money_total',$money_total);

    	$this->assign('user',$user);
        $this->display();        
    }
    
}